package com.zhinan.utils;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;

/**
 * @Description: Shiro中Session相关工具类
 * @Author: ZhiNan
 * @Date: 2023-04-10 15:52
 * @Version: 1.0
 */
public class SessionUtil {

    /**
     * 根据key从Session中查询对象
     */
    public static Object getObjectFromSession(String key) {
        Session session = SecurityUtils.getSubject().getSession();
        return session.getAttribute(key);
    }


    /**
     * 保存对象到Session中
     */
    public static void setObjectToSession(String key, Object object) {
        Session session = SecurityUtils.getSubject().getSession();
        session.setAttribute(key, object);
    }

    /**
     * 删除Session指定key的缓存
     */
    public static void delObjetFromSession(String key){
        Session session = SecurityUtils.getSubject().getSession();
        session.removeAttribute(key);

    }
}
